package com.bfly.mall.product.controller;

import com.bfly.common.ResponseUtil;
import com.bfly.core.base.controller.BaseController;
import com.bfly.core.base.entity.ResponseData;
import com.bfly.core.security.PermissionCheck;
import com.bfly.mall.product.entity.ProductImg;
import com.bfly.mall.product.service.IProductImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品图片
 *
 * @author 长沙商脉科技有限公司
 * @date 2020/9/21 19:42
 */
@RestController
@RequestMapping(value = "/manage/product/img")
public class ProductImgController extends BaseController {

    @Autowired
    private IProductImgService imgService;

    /**
     * 获得产品图片列表
     *
     * @author 长沙商脉科技有限公司
     * @date 2020/9/23 19:52
     */
    @GetMapping(value = "/list")
    @PermissionCheck(required = false)
    public void getProductImg(HttpServletResponse response, @RequestParam(value = "productId", defaultValue = "0") int productId) {
        List<ProductImg> list = imgService.getImgs(productId);

        String[] imgs=list.stream().map(ProductImg::getUrl).toArray(String[]::new);
        ResponseUtil.writeJson(response, ResponseData.getSuccess(imgs));
    }
}